﻿<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:MvcMusicStore_BI_Client_ModelView="clr-namespace:MusicStore.Dashboard.Client.ModelView"
             xmlns:Commands="clr-namespace:MusicStore.Dashboard.Client.Commands"
             xmlns:Commands1="clr-namespace:MusicStore.Wpf.Toolkit.Commands;assembly=MusicStore.Wpf.Toolkit"
             xmlns:SalesServiceReference="clr-namespace:MusicStore.Dashboard.Client.SalesServiceReference"
             xmlns:Client="clr-namespace:MusicStore.Dashboard.Client"
             x:Class="MusicStore.Dashboard.Client.View.Sales"
             mc:Ignorable="d"
             d:DesignHeight="390"
             d:DesignWidth="545">
  <UserControl.Resources>

    <MvcMusicStore_BI_Client_ModelView:SalesVM x:Key="SalesVMDataSource"
                                               d:IsDataSource="True" />

  </UserControl.Resources>

  <Grid DataContext="{Binding Source={StaticResource SalesVMDataSource}}">
    <Grid.RowDefinitions>
      <RowDefinition Height="50" />
      <RowDefinition Height="10" />
      <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <Commands:LoadSalesByMonthCommand x:Name="LoadSalesByMonth"
                                      Sales="{Binding SalesByMonth, Mode=TwoWay}" />

    <Commands:LoadSalesByGenreCommand x:Name="LoadSalesByGenre"
                                      Sales="{Binding SalesByGenre, Mode=TwoWay}" />

    <Commands:CommandGroup x:Name="Refresh">
      <Commands:CommandItem Command="{Binding ElementName=LoadSalesByMonth}" />
      <Commands:CommandItem Command="{Binding ElementName=LoadSalesByGenre}" />
      <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
          <i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type ICommand}}}" />
        </i:EventTrigger>
      </i:Interaction.Triggers>
    </Commands:CommandGroup>
    
    <Grid Grid.Row="0"
          Style="{DynamicResource Title}">
      <TextBlock Text="Sales"
                 FontSize="24"
                 HorizontalAlignment="Center"
                 VerticalAlignment="Center"
                 Foreground="White">
        <TextBlock.Effect>
          <DropShadowEffect />
        </TextBlock.Effect>
      </TextBlock>
    </Grid>
    <Grid Grid.Row="1">
      <Grid.Background>
        <LinearGradientBrush EndPoint="0.5,1"
                             StartPoint="0.5,0">
          <GradientStop Color="#FF3F3B43" />
          <GradientStop Color="#FF968E9F"
                        Offset="1" />
        </LinearGradientBrush>
      </Grid.Background>
    </Grid>
    <Grid Grid.Row="2"
          Background="#FF968E9F">

      <Grid>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="0.5*" />
          <ColumnDefinition Width="0.5*" />
        </Grid.ColumnDefinitions>
        <chartingToolkit:Chart Title="Sales by Month"
                               Background="Transparent"
                               Margin="5"
                               Style="{StaticResource DefaultChartStyle}"
                               BorderThickness="0">
          <chartingToolkit:PieSeries DependentValuePath="Amount"
                                     IndependentValuePath="Month"
                                     ItemsSource="{Binding SalesByMonth}"
                                     IsSelectionEnabled="True" />
        </chartingToolkit:Chart>
        <Button Content="Refresh"
                Command="{Binding ElementName=LoadSalesByMonth}"
                Grid.Column="0"
                HorizontalAlignment="Right"
                VerticalAlignment="Top"
                Width="75"
                Margin="0, 10, 48, 0" />
        <chartingToolkit:Chart Grid.Column="1"
                               Title="Sales by Genre"
                               Background="Transparent"
                               Margin="5,5,4,5"
                               Style="{StaticResource DefaultChartStyle}"
                               BorderThickness="0">
          <chartingToolkit:PieSeries DependentValuePath="Amount"
                                     IndependentValuePath="Genre"
                                     ItemsSource="{Binding SalesByGenre}"
                                     IsSelectionEnabled="True" />
        </chartingToolkit:Chart>
        <Button Content="Refresh"
                Command="{Binding ElementName=LoadSalesByGenre}"
                Grid.Column="1"
                HorizontalAlignment="Right"
                VerticalAlignment="Top"
                Width="75"
                Margin="0, 10, 48, 0" />
      </Grid>

    </Grid>

    <Button Content="Refresh"
            Command="{Binding ElementName=Refresh}"
            HorizontalAlignment="Right"
            VerticalAlignment="Top"
            Width="75"
            Margin="0, 10, 48, 0" />
  </Grid>
</UserControl>